{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "_execution_state": "idle",
    "_uuid": "051d70d956493feee0c6d64651c6a088724dca2a",
    "id": "GC3FBi5L7OLq",
    "papermill": {
     "duration": 0.005457,
     "end_time": "2021-02-10T13:42:51.332609",
     "exception": false,
     "start_time": "2021-02-10T13:42:51.327152",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "# Simple Exercise on Overfitting\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "YTaOmenI7TfT"
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import statsmodels.api as sm\n",
    "import warnings\n",
    "warnings.simplefilter('ignore')\n",
    "\n",
    "\n",
    "def regression_stats(n, p):\n",
    "    np.random.seed(123)\n",
    "    X = np.random.normal(size=(n, p))\n",
    "    y = np.random.normal(size=(n, 1))\n",
    "    print(f\"p/n is: {p/n if n != 0 else np.inf}\")\n",
    "    print(f\"R^2 is {sm.OLS(y, X).fit().rsquared}\")\n",
    "    print(f\"Adjusted R^2 is {sm.OLS(y, X).fit().rsquared_adj}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "C57WYtYM7OL0",
    "papermill": {
     "duration": 0.998738,
     "end_time": "2021-02-10T13:42:52.344388",
     "exception": false,
     "start_time": "2021-02-10T13:42:51.345650",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "regression_stats(1000, 1000)\n",
    "regression_stats(1000, 500)\n",
    "regression_stats(1000, 50)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "colab": {
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  },
  "papermill": {
   "default_parameters": {},
   "duration": 4.940504,
   "end_time": "2021-02-10T13:42:53.102123",
   "environment_variables": {},
   "exception": null,
   "input_path": "__notebook__.ipynb",
   "output_path": "__notebook__.ipynb",
   "parameters": {},
   "start_time": "2021-02-10T13:42:48.161619",
   "version": "2.2.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
